from TestToolsV2.common.MyConfig import myConfig
from TestToolsV2.components.BaseComponent import baseComponent


class settingDialog(baseComponent):
    """
    自定义默认设置窗口
    """

    # noinspection PyCompatibility
    def __init__(self, windownName, windownUi):
        super().__init__(windownName, windownUi)

    def setDatas(self, _config: myConfig):
        self.clear_panleBox()
        panelList = _config.panelList
        blackPanel = _config.blackPanel
        panelList.remove(blackPanel)
        panelList.insert(0, blackPanel)
        self.set_panleBox_items(panelList)  # 设置主题选择框
        self.set_pathEdit_text(_config.defualExcelPath)  # 设置默认路径
        self.set_colorEdit_text(_config.highColor)  # 设置高亮颜色
        self.set_sizeEdit_text(_config.highSize)  # 设置高亮字体大小
        self.set_historyPathEdit_list(_config.histryPath)  # 设置历史路径

    def clear_panleBox(self):
        """
        移除控件中所有值
        """
        self.clear_comboBox("panleBox")

    def getDatas(self) -> dict:
        """
        获取 settingDialog 弹窗的所有控件的值\n
        返回一个 控件名：控件值 的字典
        """
        mydict = {"blackPanel": self.get_panleBox_item(), "highColor": self.get_colorEdit_text(),
                  "highSize": self.get_sizeEdit_text(), "defualExcelPath": self.get_pathEdit_text(),
                  "histryPath": self.get_historyPathEdit_list()}
        return mydict

    def set_panleBox_items(self, datalist: list):
        """
        设置 panleBox主题列表 数据
        """
        self.set_comboBox_Items("panleBox", datalist)

    def set_pathEdit_text(self, text: str):
        """
        设置 pathEdi默认路径 值
        """
        self.set_lineEdit_value("pathEdit", text)

    def set_colorEdit_text(self, text: str):
        """
        设置 colorEdit高亮颜色 值
        """
        self.set_lineEdit_value("colorEdit", text)

    def set_sizeEdit_text(self, text: str):
        """
        设置 sizeEdit字体大小 值
        """
        self.set_lineEdit_value("sizeEdit", text)

    def set_historyPathEdit_appList(self, datalist: list):
        """
        设置 historyPathEdit历史路径 值
        """
        for data in datalist:
            self.set_plainEdit_appText("historyPathEdit", data)

    def set_historyPathEdit_list(self, datalist: list):
        """
        设置 historyPathEdit历史路径 值
        """
        self.set_plainEdit_text("historyPathEdit", "\n".join(datalist))

    def get_panleBox_item(self) -> str:
        """
        获取 panleBox主题列表 选中值
        """
        return self.get_comboBox_value("panleBox")

    def get_pathEdit_text(self) -> str:
        """
        获取 pathEdi默认路径 值
        """
        return self.get_lineEdit_value("pathEdit")

    def get_colorEdit_text(self) -> str:
        """
        获取 colorEdit高亮颜色 值
        """
        return self.get_lineEdit_value("colorEdit")

    def get_sizeEdit_text(self) -> str:
        """
        获取 sizeEdit字体大小 值
        """
        return self.get_lineEdit_value("sizeEdit")

    def get_historyPathEdit_list(self) -> list:
        """
        获取 historyPathEdit历史路径 数据列表
        """
        return self.get_plainEdit_value("historyPathEdit").splitlines()

    def get_result(self):
        return self.get_windownUi().result()
